<?php
namespace Entities\Intelihelp;

use Doctrine\ORM\Query;
use Doctrine\ORM\EntityRepository;

class TipoRepository extends EntityRepository
{
	public function listar($params = array())
	{
		$qb		= $this->getEntityManager()->createQueryBuilder();
		$qb->select('t')
		->from('Entities\Intelihelp\Tipo', 't');

		$where	= $qb->expr()->andX();
		$where->add($qb->expr()->eq(1,1));
		foreach ($params as $key => $value)
		{
			$where->add($qb->expr()->eq($key, $value));
		}
		$qb->where($where);
		$qb->orderBy('t.ds_tipo', 'ASC');

		return $qb->getQuery()->getResult(Query::HYDRATE_OBJECT);
	}

	public function listCombo()
	{
		$criteria	= array('t.fl_ativo' => 1);
		$return	= array();
		foreach ($this->listar($criteria) as $value)
		{
			$return[$value->get('id_tipo')]	= $value->get('ds_tipo');
		}
		return $return;
	}
}